package com.fzj.example.design.flyweight;

import java.util.HashMap;

/**
* @Description 享元工厂
* @Author  fanzj
* @Date   2020/5/10 3:07 下午
* @Param
* @Return
* @Exception
*
*/
public class FlyweightFactory {
    private HashMap<String,Flyweight> flyweights=new HashMap<>();

    public Flyweight getFlyweight(String key){
        Flyweight flyweight=this.flyweights.get(key);
        if (flyweight != null) {
            System.out.println("已经被占据");
        }else{
            flyweight=new ConcreteFlyweight(key);
            flyweights.put(key,flyweight);
        }
        return  flyweight;
    }
}
